package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
)
type Response struct {
	Code int
	Msg string
	Data interface{}
}
func main() {
	r := gin.Default()

	// 返回Json--map
	r.GET("/json_map", func(context *gin.Context) {
		path := context.FullPath()
		fmt.Println(path)
		// map类型转换为json
		context.JSON(200, map[string]interface{}{
			"code":200,
			"msg":"ok",
			"data":"json",
		})
	})

	// 返回Json--结构体
	r.GET("/json_struct", func(context *gin.Context) {
		path := context.FullPath()
		fmt.Println(path)
		//map类型转换为json
		//实例化一个结构体
		resp := Response{
			Code: 200,
			Msg: "OK",
			Data:path,
		}
		context.JSON(200,&resp)
	})
	r.Run("127.0.0.1:8005")
}
